import 'babel-polyfill'
import Vue from 'vue'
import VueRouter from 'vue-router'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import Index from './views/index.vue'
import PersonalRanking from './views/personalRanking.vue'
import bridge from './bridge'
import FastClick from 'fastclick'
import axios from 'axios'
import MyHomePage from './views/myHomePage.vue'
import OtherHomePage from './views/otherHomePage.vue'
import PraiseList from './views/praiseList.vue'
import SelectView from './views/selectView.vue'
import TeamHomePage from './views/teamHomePage.vue'
import Question from './views/question.vue'
import QuestionList from './views/questionList.vue'
import Invite from './views/invite.vue'
import Setting from './views/setting.vue'
import util from './assets/util'
import config from './assets/config'

FastClick.attach(document.body);

Vue.use(MintUI)
Vue.use(VueRouter)

Vue.prototype.$http = axios;
Vue.prototype.$eventBus = new Vue();

let date = util.unparam(location.search).date;
util.session.set('data-current-date', date);
let uuid = util.storage.get('sport-uuid');
if(!uuid) {
    bridge.ready(function () {
        bridge.client.getUUID(function (d) {
            util.storage.set('sport-uuid', d.data.uuid);
        })
    })
}

const routes = [
    { path: '/', component: Index },
    {path:'/personalRanking',component: PersonalRanking},
    {path:'/myHomePage',component: MyHomePage},
    {path:'/otherHomePage',component: OtherHomePage},
    {path:'/praiseList', component: PraiseList},
    {path:'/selectView', component:SelectView},
    {path:'/teamHomePage',component:TeamHomePage},
    {path:'/question', component:Question},
    {path:'/questionList', component:QuestionList},
    {path:'/invite', component:Invite},
    {path:'/setting', component:Setting}
];

const router = new VueRouter({
    mode:'hash',
    routes
});


const vm = new Vue({router});

vm.$http.get(config.host + config.userInfo).then((res)=>{
    var obj = res.data.data.user;
    vm.common = res.data.data.userInfo; // 公共用户信息
    if(!res.code) {
        util.session.set('sport-user-info', obj);
        util.session.set('sport-has-dept', res.data.data.isDept);
        vm.$mount('#app');
    } else {
        alert(res.msg);
    }
})
